<template>
	<div class="wrapper">
		<!--header部分-->
		<header>
			<div class="back" @click="toWallet">
			<i class="fa fa-chevron-left"></i>
			</div>
			<div class="text">绑定银行卡</div>
		</header>
		<!-- 表单部分 -->
		<ul class="form-box">
			<li>
				<div class="title">
					银行卡号码：
				</div>
				<div class="content">
					<input type="text" v-model="cartId" placeholder="银行卡号码">
				</div>
			</li>
			<li>
				<div class="title">
					银行卡密码：
				</div>
				<div class="content">
					<input type="password" v-model="cartPassword" placeholder="银行卡密码">
				</div>
			</li>
		</ul>
		<div class="button-bind">
			<button @click="bind">绑定</button>
		</div>
	</div>
</template>

<script>
	export default{
		name:'bind',
		data(){
			return{
				cartId:'',
				cartPassword:'',
				balance:'',
				user:{},
			}
		},
		created(){
			this.user = this.$getSessionStorage('user');
		},
		methods:{
			toWallet() {
				this.$router.push({
					path: '/wallet'
				});
			},
			bind(){
				if (this.cart == '') {
					alert('银行卡号码不能为空！');
					return;
				}
				if (this.cartPassword == '') {
					alert('银行卡密码不能为空！');
					return;
				}
				//绑定请求
				this.$axios.post('UserCartController/getUserCartByIdByPass', this.$qs.stringify({
					cartId: this.cartId,
					cartPassword: this.cartPassword,
				})).then(response => {
					let usercart = response.data;
					if (usercart.cartId == null) {
						alert('卡号或密码不正确！');
					} else {
						//sessionstorage有容量限制，为了防止数据溢出，所以不将userImg数据放入session中
						this.$axios.post('UserController/addUserCartById',this.$qs.stringify({
							userId:this.user.userId,
							cartId: this.cartId,
							cartPassword: this.cartPassword,
						})).then(response=>{
							
						}).catch(error=>{
							console.error(error);
						});
						
						this.$axios.post('UserCartController/addUserById',this.$qs.stringify({
							userId:this.user.userId,
							cartId:this.cartId
						})).then(response=>{
							
						}).catch(error=>{
							console.error(error);
						});
						
						this.$router.go(-1);
						
					}
				}).catch(error => {
					console.error(error);
				});
			},
		}
	}
</script>

<style scoped>
	/****************** 总容器 ******************/
	.wrapper {
		width: 100%;
		height: 100%;
		background-color: azure;
	}
	/****************** header ******************/
	.wrapper header{
		width: 100%;
		height: 12vw;
		background-color: #FFF;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		margin-bottom: 1vw;
	}
	.wrapper header .back{
		font-size: 4vw;
		margin-left: 2vw;
		margin-right: 2vw;
	}
	.wrapper header .text{
		font-size: 4vw;
	}
	/****************** 表单部分 ******************/
	.wrapper .form-box {
		width: 100%;
		
	}
	
	.wrapper .form-box li {
		box-sizing: border-box;
		padding: 4vw 3vw 0 3vw;
		display: flex;
		align-items: center;
	}
	
	.wrapper .form-box li .title {
		flex: 0 0 18vw;
		font-size: 3vw;
		font-weight: 700;
		color: #666;
	}
	
	.wrapper .form-box li .content {
		flex: 1;
	}
	
	.wrapper .form-box li .content input {
		border: none;
		outline: none;
		width: 100%;
		height: 4vw;
		font-size: 3vw;
	}
	.wrapper .button-bind {
		width: 100%;
		box-sizing: border-box;
		padding: 4vw 3vw 0 3vw;
	}
	
	.wrapper .button-bind button {
		width: 100%;
		height: 10vw;
		font-size: 3.8vw;
		font-weight: 700;
		color: #fff;
		background-color: #38CA73;
		border-radius: 4px;
		border: none;
		outline: none;
	}
</style>
